←Select platform

WriteTags(Stream,int,IEnumerable<RasterTagMetadata>) Method

Summary
Writes or changes one or more tags to an existing stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void WriteTags( 
   Stream stream, 
   int pageNumber, 
   IEnumerable<RasterTagMetadata> tags 
) 
- (BOOL)writeTags:(nullable NSArray<LTRasterTagMetadata *> *)tags  
         toStream:(LTLeadStream *)stream  
       pageNumber:(NSInteger)pageNumber  
            error:(NSError **)error 
public void writeTags(ILeadStream stream, int pageNumber, RasterCollection<RasterTagMetadata> tags) 
public: 
void WriteTags(  
   Stream^ stream, 
   int pageNumber, 
   IEnumerable<RasterTagMetadata^>^ tags 
)  
def WriteTags(self,stream,pageNumber,tags): 

Parameters

stream
A Stream that contains the file data.

pageNumber
1-based index of the page at which to write the tag.

tags
A collection of RasterTagMetadata objects to identify the data in the TIFF file.

Remarks

This method writes tags into an existing file or changes tags in an existing file.

This method with TIFF and other files that support Exif metadata (JPEG, PNG).

Note Use this method carefully. LEADTOOLS will not restrict the tags that you write. If you write bad tags, the file might become corrupted. Consult the TIFF documentation for a list of predefined tags. It is recommended that you write only the user-defined tags (the tags between 0x8000 and 0xFFFF).

See the TIFF documentation for a complete list of the TIFF tags and types.

Some restrictions apply to this function if you use an IFD to indicate to which page to write the comment. See the Loading and Saving Large TIFF / BigTIFF Files topic for more information.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
string tagsFileName; 
IList<RasterTagMetadata> myTags; 
 
void EnumTagsExample(string srcFileName, string destFileName) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   tagsFileName = srcFileName; 
   myTags = new List<RasterTagMetadata>(); 
 
   codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound); 
   codecs.EnumTags(srcFileName, 1); 
   codecs.TagFound -= new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound); 
 
   // We read all the tags now, save them to the file 
   Debug.WriteLine("{0} tags read, saving them to the destination file", myTags.Count); 
   codecs.WriteTags(destFileName, 1, myTags); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e) 
{ 
   Debug.WriteLine("Tag: Id={0}, Count={1}, Type={2}, Cancel={3}", e.Id, e.Count, e.MetadataType, e.Cancel); 
 
   // Read this tag from the file and add it to our collection 
   RasterCodecs codecs = sender as RasterCodecs; 
   RasterTagMetadata tag = codecs.ReadTag(tagsFileName, 1, e.Id); 
   myTags.Add(tag); 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
String tagsFileName; 
RasterCollection<RasterTagMetadata> myTags; 
 
public void enumTagsExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "ocr1-4.tif"); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   tagsFileName = srcFileName; 
   myTags = new RasterCollection<RasterTagMetadata>(); 
 
   ILeadStream srcFileStream = LeadStreamFactory.create(srcFileName); 
   codecs.addTagFoundListener(codecsTagFound); 
   codecs.enumTags(srcFileStream, 1); 
   codecs.removeTagFoundListener(codecsTagFound); 
 
   // We read all the tags now, save them to the file 
   System.out.println(myTags.size() + " tags read, saving them to the destination file"); 
   ILeadStream destFileStream = LeadStreamFactory.create(srcFileName); 
   codecs.writeTags(destFileStream, 1, myTags); 
 
   // Clean up 
   destFileStream.close(); 
   srcFileStream.close(); 
   codecs.dispose(); 
} 
 
CodecsTagFoundListener codecsTagFound = new CodecsTagFoundListener() { 
 
   @Override 
   public void onTagFound(CodecsEnumTagsEvent e) { 
      System.out.println("Tag: Id=" + e.getId() + ", Count=" + e.getCount() + ", Type=" + e.getMetadataType() 
            + ", Cancel=" + e.getCancel()); 
 
      // Read this tag from the file and add it to our collection 
      RasterCodecs codecs = (RasterCodecs) e.getSource(); 
      ILeadStream ls = LeadStreamFactory.create(tagsFileName); 
      RasterTagMetadata tag = codecs.readTag(ls, 1, e.getId()); 
      myTags.add(tag); 
      try { 
         ls.close(); 
      } catch (IOException e1) { 
         e1.printStackTrace(); 
      } 
   } 
 
}; 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.